<?

class Createbook extends TPage
{
	public $id = -1;
    /**
     * Initializes the inputs with existing user data.
     * This method is invoked by the framework when the page is being initialized.
     * @param mixed event parameter
     */
    public function onInit($param)
    {
        $this->id = $this->Request['id'];
    }
	public function createbookSubmit($bookResult)
	{
		$url = $this->Service->constructUrl('users.BooksUser',array('id' => $this->user->ID,'resultcreatebook'=>$bookResult));

        $this->Response->redirect($url);	
	}
	public function createBookSubmitRequest()
	{
		$createdata = $this->Temp_data->value;
		$bookname = $this->BookName->Text;
		$bookdesc = $this->BookDesc->Text;
		$datapieces = explode(",", $createdata);
		//die($createdata."<br>".$bookname."<br>".$bookdesc."<br>".$datapieces[0]."<br>".$datapieces[1]."<br>".$datapieces[2]."<br>");	
	
		$userRecord = new BookDataRecord;
		$userRecord->book_name = $this->BookName->Text;
		$userRecord->book_desc = $this->BookDesc->Text;
		$userRecord->book_page_src = $datapieces[0];
		$userRecord->book_binder_src = $datapieces[1];
		$userRecord->book_bg_src = $datapieces[2] ; 
		//$userRecord->p1 = $this->getDefaultP1XML(); 
		// save it
		$userRecord->save();
		$bookResult =  0 ;
		if($userRecord->book_id>0)
		{
		$book = new BookIDRecord;
		$book->user_id = $this->id;		
		$book->book_id = $userRecord->book_id;
		$book->save();
		$bookResult =  200 ;
		}
		else
		{
		$bookResult =  400 ;
		}
		$this->createbookSubmit($bookResult);
		
	}
 
	public function getDefaultP1XML()
	{
		return "<?xml version=\"1.0\" encoding=\"WINDOWS-874\"?><bookpage value=\"1\"><content><propertystyle><left value=\"168px\"></left><top value=\"49px\"></top><width value=\"150px\"></width><height value=\"150px\"></height></propertystyle><innerhtml type=\"html\">Welcome to Bookapon.com<br></innerhtml></content><bookimage><src value=\"http://localhost/smartbooktrunk/assets/Pic/image/icon_update.png\"></src><propertystyle><left value=\"186px\"></left><top value=\"221px\"></top><width value=\"123px\"></width><height value=\"119px\"></height><opacity value=\"1\"></opacity></propertystyle></bookimage></bookpage>";
	}
 
}

?>